#include <stdio.h>
#include <stdlib.h>

int main(int argc, char*argv[]) {
  /* for the gadget parameter file all one wants to change for each different run is the initial conditions file, which will determine the output filename too.
  The set of arguments necessary are:
    * output directory to put snapshot files in (make sure you can recognize with the parameters and each different seed)
    * Fnl
    * qsig
    * Np1
    * Lbox
    * ICfile
    * nproc?
  */
  if (argc!=11) {
    printf("I need 10 arguments! (seed, Fnl, qsig, Np1, Lbox, outdir, icdir, nproc, name, rscmd) instead of %d \n", argc);
    return;
  }
  else {
    int seed, Np1, Fnl, nproc, Lbox;
    float qsig;
    char fname[100];
    char icfile[200];
    FILE* fp;
    
    seed = atoi(argv[1]);
    Fnl = atoi(argv[2]);
    qsig = atof(argv[3]);
    Np1 = atoi(argv[4]);
    Lbox = atoi(argv[5]);
    nproc = atoi(argv[8]);
    
    sprintf(fname, "gadget_%d_%s.param",seed, argv[9]);
    fp = fopen(fname, "w");
    sprintf(icfile, "%s/2lptIC_%d_%s", argv[7],seed, argv[9]);
    fprintf(fp, "InitCondFile %s\n", icfile);
    fprintf(fp, "OutputDir %s\n", argv[6]);
    fprintf(fp, "EnergyFile energy.txt\nInfoFile info.txt\nTimingsFile timings.txt\nCpuFile cpu.txt\n");
    fprintf(fp, "RestartFile restart\nSnapshotFileBase snapshot\n");
    fprintf(fp, "OutputListFilename /gpfs/home/sza5154/group/FeederSim/outputs.txt\n");
    fprintf(fp, "TimeLimitCPU 600\n");
    fprintf(fp, "ResubmitOn 1\nResubmitCommand %s %s %s\n", argv[10], argv[11], argv[12]);
    fprintf(fp, "ICFormat 1\nSnapFormat 1\nComovingIntegrationOn 1\n");
    fprintf(fp, "TypeOfTimestepCriterion 0\nOutputListOn 1\nPeriodicBoundariesOn 1\n");
    fprintf(fp, "TimeBegin 0.02\nTimeMax 1.0\n");
    fprintf(fp, "Omega0 0.27\nOmegaLambda 0.73\nOmegaBaryon 0.04\nHubbleParam 0.7\n");
    fprintf(fp, "BoxSize %d.0\n", Lbox);
    fprintf(fp, "TimeBetSnapshot 0.5\nTimeOfFirstSnapshot 0\n");
    fprintf(fp, "CpuTimeBetRestartFile 72000.0\nTimeBetStatistics 0.05\n");
    fprintf(fp, "NumFilesPerSnapshot %d\nNumFilesWrittenInParallel %d\n", nproc, nproc);
    fprintf(fp, "ErrTolIntAccuracy 0.025\nMaxRMSDisplacementFac 0.2\nCourantFac 0.15\nMaxSizeTimestep 0.03\nMinSizeTimestep 0.0\n");
    fprintf(fp, "ErrTolTheta 0.5\nTypeOfOpeningCriterion 1\nErrTolForceAcc 0.005\n");
    fprintf(fp, "TreeDomainUpdateFrequency 0.1\n");
    fprintf(fp, "DesNumNgb 33\nMaxNumNgbDeviation 2\nArtBulkViscConst 0.8\nInitGasTemp 1000.0\nMinGasTemp 50.0\n");
    fprintf(fp, "PartAllocFactor 1.6\nTreeAllocFactor 0.8\nBufferSize 300\n");
    fprintf(fp, "UnitLength_in_cm 3.085678e24\nUnitMass_in_g 1.989e43\nUnitVelocity_in_cm_per_s 1e5\nGravityConstantInternal 0\n");
    fprintf(fp, "MinGasHsmlFractional 0.25\n");
    fprintf(fp, "SofteningGas 0\nSofteningHalo 0.2\nSofteningDisk 0\nSofteningBulge 0\nSofteningStars 0\nSofteningBndry 0\n");
    fprintf(fp, "SofteningGasMaxPhys 0\nSofteningHaloMaxPhys 0.2\nSofteningDiskMaxPhys 0\nSofteningBulgeMaxPhys 0\nSofteningStarsMaxPhys 0\nSofteningBndryMaxPhys 0\n");
  }
}
